package com.besovideo.mpu;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.smarteye.mpu.MPUGlobal;
import com.smarteye.mpu.MainService.Connection;
import com.smarteye.mpu.coresdk.MPUDefine;
import com.smarteye.mpu.coresdk.MPUKey;

public class RecordingDialog extends Dialog {

	Context context;
	int lay;
	private Connection mConnection;
	RadioGroup m_RadioGroup;
	private RadioButton m_RecordOpen;
	private RadioButton m_RecordClose;
	private RadioButton m_RecordAuto;

	public RecordingDialog(Context context) {
		super(context, R.style.TransparentDialogHaveTitle);
		this.context = context;
		this.lay = R.layout.recording_dialog;
		mConnection = ((MPUGlobal) ((MainActivity) context).getApplication())
				.getConnection();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.setContentView(lay);
		m_RadioGroup = (RadioGroup) findViewById(R.id.radioGroupRecord);
		m_RecordOpen = (RadioButton) findViewById(R.id.radioButtonRecordOpen);
		m_RecordClose = (RadioButton) findViewById(R.id.radioButtonRecordClose);
		m_RecordAuto = (RadioButton) findViewById(R.id.radioButtonRecordAuto);

		m_RadioGroup
				.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
					@Override
					public void onCheckedChanged(RadioGroup arg0, int checkedId) {
						// TODO Auto-generated method stub
						MainActivity parent = (MainActivity) context;
						if (checkedId == m_RecordOpen.getId()) {
							parent.mainConfigMenuListViewAdapter
									.setText(
											MainActivity.MainConfigMenuEnum.MAIN_MENU_RECODE
													.value(), m_RecordOpen
													.getText().toString());
							mConnection.setSDKOptionString(
									MPUKey.MPU_S_RECORD_FILE_NAME, "du.mkv");
							mConnection.setSDKOptionString(
									MPUKey.MPU_S_RECORD_FILE_PATH,
									"/sdcard/MPU/");
							mConnection.setSDKOptionInt(
									MPUKey.MPU_I_RECORD_VIDEO_BITRATE,
									20000 * 1000);
							mConnection.setSDKOptionInt(
									MPUKey.MPU_I_RECORD_FILE_SECONDS, 60);
							mConnection.setSDKOptionInt(
									MPUKey.MPU_I_RECORD_VIDEO_IFRAMESINTERVAL,
									1);
							mConnection
									.setSDKOptionInt(
											MPUKey.MPU_I_RECORD_MEDIA_TYPE,
											MPUDefine.MPU_FLAG_RECORD_MEDIA_AUDIO
													| MPUDefine.MPU_FLAG_RECORD_MEDIA_VIDEO);
							mConnection.setSDKOptionInt(
									MPUKey.MPU_I_RECORD_MEDIA_STATUS,
									MPUDefine.MPU_FLAG_RECORD_STATUS_OPEN);
							mConnection.storage();
						} else if (checkedId == m_RecordClose.getId()) {
							parent.mainConfigMenuListViewAdapter
									.setText(
											MainActivity.MainConfigMenuEnum.MAIN_MENU_RECODE
													.value(), m_RecordClose
													.getText().toString());
							mConnection.setSDKOptionInt(
									MPUKey.MPU_I_RECORD_MEDIA_STATUS,
									MPUDefine.MPU_FLAG_RECORD_STATUS_CLOSE);
							mConnection.storage();
						} else if (checkedId == m_RecordAuto.getId()) {
							parent.mainConfigMenuListViewAdapter
									.setText(
											MainActivity.MainConfigMenuEnum.MAIN_MENU_RECODE
													.value(), m_RecordAuto
													.getText().toString());
						}
						parent.mainConfigMenuListViewAdapter
								.notifyDataSetChanged();
						dismiss();
					}
				});
	}
}